package arrAndstr;

public class T392 {

    public static void main(String[] args) {
        String s = "abc", t = "ahbgdc";

        System.out.println(isSubsequence(s, t));
    }

    public static boolean isSubsequence(String s, String t) {
        // 每次比较，删除t的第一个字符
        int lenS = s.length();
        int lenT = t.length();
        if (lenS == 0) {
            return true;
        }


        int indexNow = 0;
        char chNow = s.charAt(indexNow);
        char[] chs = t.toCharArray();
        for(int i=0; i<lenT; i++) {
            if(chs[i] == chNow) {
                indexNow++;
            }
            if (indexNow >= lenS) {
                return true;
            }
            chNow = s.charAt(indexNow);
        }

        return false;
    }
}
